#include "headfiles.h"

using namespace std;

int jumpGame(int *a, int n) {
    int cnt = 0;
    int j, mx, i;
    j = 1;
    i = 0;
    while (i < n - 1 && i + a[i] < n - 1) {
        for (mx = j; j <= i + a[i]; j++) {
            mx = (mx + a[mx] < j + a[j]) ? j : mx;
        }
        i = mx;
        cnt++;
    }

    return cnt;
}

